
local Player = {}

Player.State = {
    None = 0,
    Match = 1,
    Offline = 2,
}

function Player:new(open_id,client)
    local o = {
        open_id = open_id or "",
        client = client or nil,
        state = Player.State.None,
    }
    setmetatable(o,self)
    self.__index = self
    return o
end

function Player:onOnline(client)
    self.client = client
    self.state = Player.State.None
end

function Player:onOffline()
    self.client = nil
    self.state = Player.State.Offline
end

function Player:isOffline()
    return Player.State.Offline == self.state
end

function Player:isInMatch()
    return Player.State.Match == self.state
end

function Player:setState(state)
    self.state = state
end

function Player:getOpenID()
    return self.open_id
end

function Player:getClient()
    return self.client
end

function Player:sendRawMessage(buf)
    if self.client then
        return self.client:sendRawMessage(buf)
    end
end

function Player:sendMessage(id,type,message)
    if self.client then
        self.client:sendMessage(id,type,message)
    end
end

return Player